package IO;

/**
 *
 * @author Sara Tily
 */

import java.io.File;
import java.io.IOException;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

public class SaveImage {
    public static void save(BufferedImage image, String path) {
		//get the extension of the image
        String ext = path.substring(path.lastIndexOf(".")+1);
        System.out.println(ext);
        System.out.println(path);
        File file = new File(path);

        try {
            ImageIO.write(image, ext, file);  // ignore returned boolean
        } catch(IOException e) {
            System.out.println(
				"Write error for " + path + ": " + e.getMessage()
			);
        }
    }
}    
    